import { lostTime } from '../../../code/util';
import { config } from '../../../config';
import { sequelize } from '../../db';
import { Model, DataTypes } from 'sequelize';
class GroupMessage extends Model {
    declare type?: string;
    declare msg?: boolean;
}

GroupMessage.init({
    UserId: DataTypes.INTEGER,
    groupName: DataTypes.STRING,
    type: DataTypes.STRING,
    msg: DataTypes.STRING(1024),
    fullUrl: {
        type: DataTypes.VIRTUAL,
        get() {
            return (this.dataValues.msg && this.dataValues.type === 'img') ? config.BASEURL + this.dataValues.msg : ''
        },
        set(value) {
            throw new Error('不要尝试设置 `fullUrl` 的值!');
        }
    },
    create: {
        type: DataTypes.VIRTUAL,
        get() {
            return lostTime(this.dataValues.createdAt)
        },
        set(value) {
            throw new Error('不要尝试设置 `create` 的值!');
        }
    },
}, {
    sequelize,
    paranoid: true
});

export default GroupMessage